from django.db import models
from user.models import User,Company


# Create your models here.
class NoticeInfo(models.Model):
    NOTICESTATE = (
        (0, u'已启用'),
        (1, u'已禁用'),
    )
    NOTICEREADSTATE = (
        (0, u'未读'),
        (1, u'已读'),
    )
    user = models.ForeignKey(
        User,
        verbose_name=u"发布者",
        on_delete=models.CASCADE,
        related_name='notice_publisher',
    )
    noticeState = models.IntegerField(
        choices=NOTICEREADSTATE,
        default=0,
        verbose_name=u"公告阅读状态",
    )
    noticeReadState = models.IntegerField(
        choices=NOTICESTATE,
        default=0,
        verbose_name=u"公告状态",
    )
    noticeContent = models.CharField(
        max_length=1600,
        verbose_name=u'通知内容',
        default=u'',
    )
    noticeTitle = models.CharField(
        max_length=50,
        verbose_name=u'通知标题',
        default=u'',
    )
    isview = models.ManyToManyField(
        Company,
        verbose_name=u"可浏览单位",
        # on_delete=models.CASCADE,
        related_name='company_isView_noticeInfo',
        # null=True
    )
    isRead = models.ManyToManyField(
        User,
        verbose_name=u"已阅读人员",
        # on_delete=models.CASCADE,
        related_name='user_isRead_notice',
        # null=True
    )
    uploadTime = models.DateTimeField(
        verbose_name=u"发布时间",
        auto_now_add=True,        
    )  
    createTime = models.DateTimeField(
        auto_now_add=True,
        verbose_name=u"创建时间",
    )    
    isActive = models.BooleanField(
        verbose_name=u'是否活跃',
        default=True,
    )

    def __unicode__(self):
        return self.uploadTime

    class Meta:
        ordering = ('createTime',)